package com.nj.dms.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nj.dms.dao.UserDao;
import com.nj.dms.dao.impl.UserDaoImpl;

/**
 * 批量删除用户控制器 1)接受客户端表单的批量选择的记录ID号 2）调用UserDao的批量删除方法进行批量删除处理 3）处理成功，返回用户列表
 * 4）处理失败，给出提示信息，返回用户列表
 */
@WebServlet(name = "DeleteAllUser", urlPatterns = { "/DelAllUser" })
public class DeleteAllUser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public DeleteAllUser() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 1)接受客户端表单的批量选择的记录ID号
		String[] ids = request.getParameterValues("delID");
		// {'1','3','5'}
		// 调用UserDao的批量删除方法进行批量删除处理
		UserDao userDao = new UserDaoImpl();
		if (userDao.deleteAllUserByBatch(ids)) {
			request.getRequestDispatcher("UserList").forward(request, response);
		} else {
			request.setAttribute("errormsg", "删除错误");
			request.getRequestDispatcher("UserList").forward(request, response);
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
